<?php
declare(strict_types=1);

namespace longhu\exceptions;

use Exception;
use longhu\Code;
use think\exception\HttpException;

abstract class MyException extends HttpException
{
    protected const HTTP_SUCCESS = 200;

    public function __construct(string $message = '', int $code = 0, Exception $previous = null, array $headers = [], $statusCode = 0)
    {
        parent::__construct($statusCode, $message ? : $this->getMyMessage($code), $previous, $headers, $code);
    }

    public function getStatusCode()
    {
        return self::HTTP_SUCCESS;
    }

    public function getMyMessage($code):string
    {
       if(empty($this->message)){
           $messageAttr = Code::$message_attr;
           return $messageAttr[$code]??'';
       }
       return  $this->message;
    }
}
